<template>
  <div class="app-container" style="padding: 8px;">
    <div class="head-container">
<!--      <treeselect class="filter-item" v-model="deptId" :options="depts" :style="style" placeholder="选择部门"
                  @select="selectFun"/> -->
      <el-input v-model="query.value" clearable placeholder="请输入搜索内容" maxlength="10" style="width: 150px;"
                class="filter-item" @keyup.enter.native="toQuery"/>
      <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px; ">
        <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column prop="userName" label="登录用户"/>
      <el-table-column prop="deptName" label="所属部门"/>
      <el-table-column prop="ip" label="IP"/>
      <el-table-column prop="browser" label="浏览器"/>
      <el-table-column prop="loginTime" label="登录时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="logoutTime" label="登出时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.logoutTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
  import initData from '@/mixins/initData'
  import { parseTime } from '@/utils/index'
  import { getDepts } from '@/api/framework/system/dept'
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'

  export default {
    mixins: [initData],
    components: { Treeselect },
    data() {
      return {
        style: 'width: 300px;',
        depts: [],
        deptId: null,
        queryTypeOptions: [
          { key: 'browser', display_name: '浏览器' },
          { key: 'ip', display_name: 'ip' }
        ]
      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
      })
      //this.getDeptDatas()
    },
    methods: {
      parseTime,
      beforeInit() {
        this.url = 'api/loginLog'
        const sort = 'loginTime,desc'
        const query = this.query
        const type = query.type
        const value = query.value
        this.params = { page: this.page, size: this.size, sort: sort,deptId:this.deptId }
        if (type && value) {
          this.params[type] = value
        }
        return true
      },
      getDeptDatas() {
        getDepts({ enabled: true }).then(res => {
          this.depts = res.content
        })
      },
      selectFun(data) {
        this.deptId = data.id
        this.init()
      }
    }
  }
</script>

<style scoped>

</style>
